package com.ftg.learn.chapter17;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author KangJx
 * @date 2021/8/13
 */
public class Student implements Comparable<Student> {

    Integer sno;

    String sname;




    public Student(Integer sno, String sname) {
        this.sno = sno;
        this.sname = sname;
    }

    public Integer getSno() {
        return sno;
    }

    public void setSno(Integer sno) {
        this.sno = sno;
    }

    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    @Override
    public int compareTo(Student o) {
        return this.getSno().compareTo(o.getSno());
    }

    @Override
    public String toString() {
        return "Student{" +
                "sno=" + sno +
                ", sname='" + sname + '\'' +
                '}';
    }

    public static void main(String[] args) {
        List<Student> stus = new ArrayList<>();
        stus.add(new Student(3,"杨猛"));
        stus.add(new Student(2,"王春花"));
        stus.add(new Student(1,"李二狗"));
        System.out.println(stus);
        Collections.sort(stus);

        System.out.println(stus);
    }

}
